﻿using Abp.Domain.Repositories;
using Abp.EntityFrameworkCore;
using AppFramework.Authorization.Users;
using AppFramework.DinosaursParkMes.DictionariesModel;
using AppFramework.EntityFrameworkCore;
using AppFramework.EntityFrameworkCore.Repositories;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppFramework.Repositories
{
    public class DictionariesRepository : AppFrameworkRepositoryBase<Dictionaries>, IDictionariesRepository
    {
        public DictionariesRepository(IDbContextProvider<AppFrameworkDbContext> dbContextProvider)
    : base(dbContextProvider)
        {

        }
        /// <summary>
        /// 查询字典详情
        /// </summary>
        /// <param name="DicId"></param>
        /// <returns></returns>
        public async Task<List<Dictionarieslist>> GetDictionary(string  DicId)
        {
            DbContext db = await GetDbContextAsync();
            var code = db.Set<Dictionaries>().Include(m => m.DictionaryDetails).Where(m => m.Dictionariesname == DicId).FirstOrDefault().Remark;
           
            IQueryable<Dictionaries> catalog = db.Set<Dictionaries>().Include(m => m.DictionaryDetails).Where(m => m.Remark == code);

            List<Dictionarieslist> dictionaryDetails = catalog.FirstOrDefault().DictionaryDetails.ToList();

            return dictionaryDetails;
        }
        /// <summary>
        /// 添加字典信息
        /// </summary>
        /// <param name="catalog"></param>
        /// <returns></returns>
        public async Task<Dictionaries> InsertDictionary(Dictionaries catalog)
        {
            var db = await GetDbContextAsync();
            Dictionaries dictionary = (await db.Set<Dictionaries>().AddAsync(catalog)).Entity;
            return dictionary;
        }
    }
}
